using System;
namespace ch.ethz.ssh2
{
	
	/// <summary> A <code>DHGexParameters</code> object can be used to specify parameters for
	/// the diffie-hellman group exchange.
	/// <p>
	/// Depending on which constructor is used, either the use of a
	/// <code>SSH_MSG_KEX_DH_GEX_REQUEST</code> or <code>SSH_MSG_KEX_DH_GEX_REQUEST_OLD</code>
	/// can be forced.
	/// 
	/// </summary>
	/// <seealso cref="Connection.setDHGexParameters(DHGexParameters)">
	/// </seealso>
	/// <author>  Christian Plattner
	/// </author>
	/// <version>  2.50, 03/15/10
	/// </version>
	
	public class DHGexParameters
	{
		/// <summary> Get the maximum group length.
		/// 
		/// </summary>
		/// <returns> the maximum group length, may be <code>zero</code> if
		/// SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
		/// </returns>
		virtual public int Max_group_len
		{
			get
			{
				return max_group_len;
			}
			
		}
		/// <summary> Get the minimum group length.
		/// 
		/// </summary>
		/// <returns> minimum group length, may be <code>zero</code> if
		/// SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
		/// </returns>
		virtual public int Min_group_len
		{
			get
			{
				return min_group_len;
			}
			
		}
		/// <summary> Get the preferred group length.
		/// 
		/// </summary>
		/// <returns> the preferred group length
		/// </returns>
		virtual public int Pref_group_len
		{
			get
			{
				return pref_group_len;
			}
			
		}
		//UPGRADE_NOTE: Final was removed from the declaration of 'min_group_len '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
		private int min_group_len;
		//UPGRADE_NOTE: Final was removed from the declaration of 'pref_group_len '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
		private int pref_group_len;
		//UPGRADE_NOTE: Final was removed from the declaration of 'max_group_len '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
		private int max_group_len;
		
		private const int MIN_ALLOWED = 1024;
		private const int MAX_ALLOWED = 8192;
		
		/// <summary> Same as calling {@link #DHGexParameters(int, int, int) DHGexParameters(1024, 1024, 4096)}.
		/// This is also the default used by the Connection class.
		/// 
		/// </summary>
		public DHGexParameters():this(1024, 1024, 4096)
		{
		}
		
		/// <summary> This constructor can be used to force the sending of a
		/// <code>SSH_MSG_KEX_DH_GEX_REQUEST_OLD</code> request.
		/// Internally, the minimum and maximum group lengths will
		/// be set to zero.
		/// 
		/// </summary>
		/// <param name="pref_group_len">has to be &gt= 1024 and &lt;= 8192
		/// </param>
		public DHGexParameters(int pref_group_len)
		{
			if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED))
				throw new System.ArgumentException("pref_group_len out of range!");
			
			this.pref_group_len = pref_group_len;
			this.min_group_len = 0;
			this.max_group_len = 0;
		}
		
		/// <summary> This constructor can be used to force the sending of a
		/// <code>SSH_MSG_KEX_DH_GEX_REQUEST</code> request.
		/// <p>
		/// Note: older OpenSSH servers don't understand this request, in which
		/// case you should use the {@link #DHGexParameters(int)} constructor.
		/// <p>
		/// All values have to be &gt= 1024 and &lt;= 8192. Furthermore,
		/// min_group_len &lt;= pref_group_len &lt;= max_group_len.
		/// 
		/// </summary>
		/// <param name="min_group_len">
		/// </param>
		/// <param name="pref_group_len">
		/// </param>
		/// <param name="max_group_len">
		/// </param>
		public DHGexParameters(int min_group_len, int pref_group_len, int max_group_len)
		{
			if ((min_group_len < MIN_ALLOWED) || (min_group_len > MAX_ALLOWED))
				throw new System.ArgumentException("min_group_len out of range!");
			
			if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED))
				throw new System.ArgumentException("pref_group_len out of range!");
			
			if ((max_group_len < MIN_ALLOWED) || (max_group_len > MAX_ALLOWED))
				throw new System.ArgumentException("max_group_len out of range!");
			
			if ((pref_group_len < min_group_len) || (pref_group_len > max_group_len))
				throw new System.ArgumentException("pref_group_len is incompatible with min and max!");
			
			if (max_group_len < min_group_len)
				throw new System.ArgumentException("max_group_len must not be smaller than min_group_len!");
			
			this.min_group_len = min_group_len;
			this.pref_group_len = pref_group_len;
			this.max_group_len = max_group_len;
		}
	}
}